﻿using Drempelvrij.UI.Web.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;

namespace Drempelvrij.UI.Web.Controllers
{
    public class ContactController : Controller
    {
        private string mailDrempelvrij = "ronaldme.test@gmail.com";

        public ActionResult Index()
        {
            return View();
        }
        
        [HttpPost]
        public ActionResult SendMail(ContactViewModel contact)
        {
            string naamAfzender = contact.name;
            string emailAfzender = contact.email;
            string reactieAfzender = contact.reactie;


            var smtp = new System.Net.Mail.SmtpClient();

            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(mailDrempelvrij, "welkom123");
            smtp.Timeout = 20000;

            smtp.Send(emailAfzender, mailDrempelvrij, "Reactie Drempelvrij", naamAfzender +
                                " heeft u het volgende bericht gestuurd: " + Environment.NewLine +
                                                                             Environment.NewLine + reactieAfzender);

            return Redirect("/Contact");
        }
    }
}
